package com.alarm.app.Tools;

import android.app.ActivityManager;
import android.content.Context;

import com.alarm.app.AlarmApplication;

import java.util.List;

/**
 * Desc:
 * 通用的工具类
 * Created by Hym on 2016/1/30 15:13.
 * Modified by
 * Modification：
 */
public class Ctool {
    /**
     * 判断一个应用是否为前台运行状态
     * @return
     */
    public static boolean isRunningForeground() {
        final Context context = AlarmApplication.getInstance();
        final String packageName = context.getPackageName();
        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
        if(tasksInfo.size() > 0){
            if(packageName.equals(tasksInfo.get(0).topActivity.getPackageName())){
                return true;
            }
        }
        return false;
    }
}
